import express from 'express';
import * as secondHandController from '../secondHand/secondHand.controller';
import { fileInterceptor, fileProcessor } from './secondHand.middleware';
import { validateLoginData, authGuard, userGuard } from '../auth/auth.middleware';

const router = express.Router();

/**
 * 获取内容
 */
router.get('/secondHand', userGuard, secondHandController.index);

/**
 * 获取内容(按 ID)
 */
router.get('/secondHand/:postId', userGuard, secondHandController.secondHandDetail);

/**
 * 按关键字查询（模糊查询）
 */
router.get('/getSecondHandByKey', secondHandController.selectByKey);

/**
 * 创建内容
 */
router.post('/secondHand', authGuard, secondHandController.store);

/**
 * 更新内容
 */
router.patch('/secondHand/:postId', authGuard, secondHandController.update);

/**
 * 删除内容
 */
router.post('/secondHandDestroy', authGuard, secondHandController.destroy);

/**
 * 修改状态
 */
router.patch('/secondHand', authGuard, secondHandController.status);

/**
 * 上传文件
 */
router.post('/secondHandFiles', authGuard, fileInterceptor, fileProcessor, secondHandController.uploads);

/**
 * 文件服务
 */
router.get('/secondHandFiles/:fileId/serve', secondHandController.serve);

/**
 * 获取文件 ID
 */
router.post('/getSecondHandFilesId', secondHandController.getFileName)

/**
 * 导出路由
 */
export default router;
